<?php
class Category extends Model {
	
	public function isRoot()
	{
		return $tthis->level == 0;
	}
	
	public function hasDescendants()
	{
		return $this->rgt - $this->lft > 1;
	}
	
	public function hasAncestors()
	{
		return ! $this->isRoot();
	}
	
	public function getDescendants()
	{
		return CategoryManager::getInstance()->getDescendants($this);
	}
	
	public function getChildren()
	{
		return CategoryManager::getInstance()->getChildren($this);
	}
	
	public function getBooks()
	{
		return BookManager::getInstance()->getByCategoryId($this->id);
	}
	
	public function addBook(Book $book)
	{
		return BookManager::getInstance()->addBookToCategory($book, $this);
	}
}